<template>
  <div>
        <el-tree 
            v-if="this.dataStructType == 1"
            :data="treeData"
            :props="defaultProps"
            icon-class="ivu-icon-ios-arrow-forward">
        </el-tree>

        <InnerPageTable 
            ref="dataSourceTable" 
            v-else
            :config="tableConfig"> 
        </InnerPageTable>
  </div>
</template>

<script>
import { delDimensionDataSource, getDimenionData } from "@/api/dimensionApi.js";
import locales from "./locales.js";
import { previewSource } from "./columns.js";
export default {
    mixins: [locales],
    props: {
        dataStructType: {
            type: Number,
            default() {
                return false
            }
        },
        dimensionDataUrl: {
            type: String,
            default() {
                return ""
            }
        }
    },
    data() {
        return {
            treeData: [],
            defaultProps: {
                children: 'children',
                label: 'text'
            },
        }
    },
    created() {
        this.init()
    },
    computed: {
        tableConfig() {
            return {
                loadDataFn: this.getLoadDataList,
                columnsFn: previewSource.bind(this),
                initParam: { dimensionDataUrl: this.dimensionDataUrl, dataStructType: this.dataStructType },
                autoFirst: true,
                isPage: false
            };
        }
    },
    methods: {
        // 获取列表类型数据
        getLoadDataList({ responseProcess, param }) {
            getDimenionData(param).then(res => {
                responseProcess(res.data.dimensionDataListPageVo)
            })
        },
        // 获取树类型数据
        getLoadDataTree() {
            let param = {
                dimensionDataUrl: this.dimensionDataUrl, 
                dataStructType: this.dataStructType
            }
            getDimenionData(param).then(res => {
                this.treeData = res.data.dimensionDataTreeVoList
            })
        },
        init() {
            this.$emit("SetTitle", this.$t("module.dimension.previewData"))
            this.$emit("SetPageWidth", 700);
            // this.$emit("SetPageActions", [
            // {
            //     text: this.$t("common.close"),
            //     theme: "primary",
            //     handle: () => {
            //     this.$emit("Close");
            //     }
            // }
            // ])
            // this.dataStructType == 1代表为树类型
            if(this.dataStructType == 1) {
                this.getLoadDataTree()
            }

        }
    }
}
</script>

<style>

</style>